package com.ordertracker.persistent.dictionary;

import com.ordertracker.persistent.dictionary.template.AbstractEmployeeTemplate;

import javax.persistence.*;

/**
 * Description of class.
 * Created 1/18/13 4:26 PM
 *
 * @author andrey.rodin@playtech.com
 */

@Entity
public class Employee extends AbstractEmployeeTemplate {
    private static final long serialVersionUID = -2836943336076289380L;

    @ManyToOne(optional = false)
    private Role role;

    @ManyToOne(optional = false)
    private User user;

    @ManyToOne(optional = false)
    private Organization organization;

    @ManyToOne(optional = false)
    private Position position;

    public Employee() {
    }

    public Employee(Role role, User user, Organization organization, Position position) {
        this.role = role;
        this.user = user;
        this.organization = organization;
        this.position = position;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public Position getPosition() {
        return position;
    }

    public void setPosition(Position position) {
        this.position = position;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Employee)) return false;
        if (!super.equals(o)) return false;

        Employee employee = (Employee) o;

        if (!organization.equals(employee.organization)) return false;
        if (!role.equals(employee.role)) return false;
        if (!user.equals(employee.user)) return false;
        if (!position.equals(employee.position)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + role.hashCode();
        result = 31 * result + user.hashCode();
        result = 31 * result + organization.hashCode();
        result = 31 * result + position.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "role=" + role +
                ", user=" + user +
                ", organization=" + organization +
                ", position=" + position +
                ", " + super.toString();
    }
}
